<?php

namespace app\api\controller\ykjp\information\basisinfo;

use app\common\controller\Api;

/**
 * 仓库信息
 *
 * @icon fa fa-circle-o
 */
class Warehouse extends Api {

    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = '*';
    /**
     * 查看
     */
    public function index()
    {
        $this->model = new \app\admin\model\ykjp\information\basisinfo\Warehouse;
        $row = $this->model->where('deletetime',null)->select();
        $this->success('返回成功', ['data' => $row]);
    }

    /**
     * 查看详情
     */
    public function getdetails()
    {
        $id = input('post.id');
        $this->model = new \app\admin\model\ykjp\information\basisinfo\Warehouse;
        $row = $this->model->where('id',$id)->select();
        $this->success('返回成功', ['data' => $row]);
    }

    /**
     * 删除
     */
    public function deleteProduct()
    {
        $id = input('post.id');
        $row = \app\admin\model\ykjp\information\basisinfo\Warehouse::where("id", $id)->delete();
        $this->success('返回成功', ['data' =>'删除成功！']);
    }

    
    /**
     * 添加
     */
    public function add(){
        $name = input('post.name');
        $linkman = input('post.linkman');
        $address = input('post.address');
        $city = input('post.city');
        $remark = input('post.remark');
        $phone = input('post.phone');
        $type = input('post.type');

        $model = new \app\admin\model\ykjp\information\basisinfo\Warehouse;
        $number="CK".date("YmdHis",time());
        $time = time();
        

        $model->insert([
            'name' => $name,
            'linkman' => $linkman,
            'address' => $address,
            'city' => $city,
            'remark' => $remark,
            'phone' => $phone,
            'type' => $type,
            'number' => $number,
            'createtime' => $time,
            'inventory'=>0,
            'updatetime' => $time
        ]);

        $this->success('返回成功', ['data' =>'添加成功！']);
    }

}

